package operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Add implements IOperation{
    @Override
    public void work (BookList bookList) {
        System.out.println ("增加图书");
        Scanner p=new Scanner (System.in);
        System.out.println ("输入书名:");
        String name=p.nextLine ();
        System.out.println ("输入作者名字：");
        String author=p.nextLine ();
        System.out.println ("输入价格");
        int price=p.nextInt ();
        System.out.println ("输入类型");
        String type=p.nextLine ();

        Book book=new Book (name,author,price,type);
        int currentsize=bookList.getUsedSize ();
        for (int i = 0; i <currentsize ; i++) {
            Book now=bookList.getBooks (i);
            if(now.getName ().equals (name)) {
                System.out.println ("要添加的书已经存在");
                return;
            }
        }
        bookList.setBook (currentsize,book);
        bookList.setUsedSize (currentsize+1);
    }


}
